package org.jeecg.modules.device;

import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import org.jeecg.boot.starter.rabbitmq.client.RabbitMqClient;
import org.jeecg.modules.driver.DeviceDriver;

import java.util.Calendar;
import java.util.Map;


public abstract class Device {

    /**主键*/
    String id;

    /**设备版本*/
    String version;

    /**影子*/
    JSONObject shadow;

    /**
     * 驱动
     */
    DeviceDriver deviceDriver;

    public JSONObject getOldData() {
        return oldData;
    }

    public void setOldData(JSONObject oldData) {
        this.oldData = oldData;
    }

    /**旧影子状态*/
    JSONObject oldData;


    /**IP**/
    String ipAddr;

    /**Port**/
    String port;

    /**在线状态**/
    String onStatus;

    /**激活状态**/
    String ison;

    public abstract void online(Boolean isManual);

    public abstract void offLine(Boolean isManual);

    public abstract Boolean login();

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getVersion() {
        return version;
    }

    public void setVersion(String version) {
        this.version = version;
    }

    public JSONObject getShadow() {
        return shadow;
    }

    public void setShadow(JSONObject shadow) {
        this.shadow = shadow;
    }

    public String getIpAddr() {
        return ipAddr;
    }

    public void setIpAddr(String ipAddr) {
        this.ipAddr = ipAddr;
    }

    public String getPort() {
        return port;
    }

    public void setPort(String port) {
        this.port = port;
    }

    public String getOnStatus() {
        return onStatus;
    }

    public void setOnStatus(String onStatus) {
        this.onStatus = onStatus;
    }

    public String getIson() {
        return ison;
    }

    public void setIson(String ison) {
        this.ison = ison;
    }

    public abstract String getNewChannelWarning();

    public abstract Map<Integer,String> getNewDeviceWarning();

    public DeviceDriver getDeviceDriver() {
        return deviceDriver;
    }

    public void setDeviceDriver(DeviceDriver deviceDriver) {
        this.deviceDriver = deviceDriver;
    }

    public boolean getIsManualDisconnect(){
        try {
            if(shadow.getInt("manualDisconnect") == 0 )
                return false;
            else
                return true;
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return false;
    }

}
